/**
 * @Author：ming
 * @Date：2023/9/26 1:15 PM
 * @Filename：Lc242
 */

import java.util.HashMap;

/**
 * @author ming
 */
public class Lc242 {
    public boolean isAnagram(String s, String t) {
        if(s.length()!=t.length()){
            return false;
        }

        char[] cs = s.toCharArray();
        char[] ct = t.toCharArray();

        HashMap<Character, Integer> smap = new HashMap<>();
        HashMap<Character, Integer> tmap = new HashMap<>();

        for (int i = 0; i < cs.length; i++) {
            if(smap.containsKey(cs[i])){
                smap.put(cs[i],smap.get(cs[i])+1);
            }else {
                smap.put(cs[i],1);
            }


            if(tmap.containsKey(ct[i])){
                tmap.put(ct[i],tmap.get(ct[i])+1);
            }else {
                tmap.put(ct[i],1);
            }
        }

        if(smap.size()!=tmap.size()){
            return false;
        }


        for (Character c : smap.keySet()) {

            if(smap.get(c).equals(tmap.get(c))){
                continue;
            }else {
                return  false;
            }
        }

        return true;

    }
}
